package com.RedRiver.hospitalsystem.personal_service.app.controller;


import com.RedRiver.hospitalsystem.personal_service.service.Form.DoctorSchedulesForm;
import com.RedRiver.hospitalsystem.personal_service.service.Form.NewDoctorSchedulesForm;
import com.RedRiver.hospitalsystem.personal_service.service.Form.PageForm;
import com.RedRiver.hospitalsystem.personal_service.service.Form.RegisterInformationForm;
import com.RedRiver.hospitalsystem.personal_service.service.ScheduleService;
import com.RedRiver.hospitalsystem.personal_service.service.info.ScheduleDoctorInfo;
import com.RedRiver.hospitalsystem.personal_service.service.info.SchedulePageInfo;
import com.RedRiver.hospitalsystem.personal_service.service.info.SubjectPageInfo;
import com.RedRiver.hospitalsystem.result.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@RestController
@RequestMapping("/schedule")
@Api(tags = "排班管理接口")
public class ScheduleController {

   @Autowired
   private ScheduleService scheduleService;

   @ApiOperation("创建某科室的医生排班信息")
   @PostMapping("/IncreaseSchedules")
   public Result<?> IncreaseSchedules(@RequestBody NewDoctorSchedulesForm newDoctorSchedulesForm){
      return scheduleService.increaseSchedules(newDoctorSchedulesForm);
   }

   @ApiOperation("分页查询所有科室的排班信息")
   @PostMapping("/findAllSchedules")
   public Result<IPage> findAllSchedules(@RequestBody PageForm form){
      IPage<SchedulePageInfo> byPage = scheduleService.findPageSchedule(form);
      return  Result.getInstance(IPage.class).setMsg("分页成功").setData(byPage);
   }

   @ApiOperation("根据排班日期和时间更新排班信息")
   @PostMapping("/updateSchedules")
   public Result<?> updateSchedules(@RequestBody DoctorSchedulesForm doctorSchedulesForm){
      return scheduleService.updateSchedule(doctorSchedulesForm);
   }

   @ApiOperation("根据id删除排班信息")
   @PostMapping("/delSchedules")
   public Result<?> delSchedules(@PathVariable("schedulesId") Integer schedulesId){
      return scheduleService.deleteSchedule(schedulesId);
   }

   @ApiOperation("挂号判断医生是否上班，是则挂号成功，否则挂号失败")
   @PostMapping("/registerInformation")
   public Result<Integer> registerInformation(@RequestBody RegisterInformationForm registerInformationForm){
      return scheduleService.registerInformationByDoctorId(registerInformationForm);
   }

   @ApiOperation("取消之前挂的号，恢复挂号人数")
   @PostMapping("/cancelRegisterInfomation")
   public Result<Integer> cancelRegisterInfomation(@RequestBody RegisterInformationForm registerInformationForm){
      return scheduleService.cancelRegisterInformationByDoctorId(registerInformationForm);
   }

   @ApiOperation("根据医生id，查看排班的科室名")
   @PostMapping("/selDoctor/{id}")
   public Result<List<ScheduleDoctorInfo>> selDoctor(@PathVariable("id") Integer id){
      return scheduleService.findDoctor(id);
   }

}

